import React, { useEffect, useState } from "react";
import DataStructure from "./components/DataStructure";
import ProjectToolBar from "./components/ProjectToolBar";
import { CpasIcon, DevToolBar, } from '~/public/cpas-ui';
import { Item } from 'devextreme-react/toolbar';
import "./index.less"
import { useModel } from "umi";
import { getAccountInfo } from "../statementProject/service"

const statementProject = () => {

    const { initialState } = useModel('@@initialState');
    const { dbname } = initialState?.curPart as API.CurPart;
    const [AccountData, setAccountData] = useState<any[]>([])
    const [DefaultData_ID, setDefaultData_ID] = useState<string>('')
    const [AccountData_ID, setAccountData_ID] = useState<string | null>('')

    const AccountInfo = async () => {
        const r = await getAccountInfo({ dbname })
        setDefaultData_ID(r[0].Data_ID)
        setAccountData(r);
    }

    useEffect(() => {
        AccountInfo()
        const v = window.localStorage.getItem('Data_Id')
        setAccountData_ID(v)
    }, [])

    const onSelectionChangeds = (e: any, v: any) => {
        setAccountData_ID(v.Data_ID);
    }

    return (
        <>
            {/* 报表项目对应  */}
            <div style={{ width: "100%", height: "calc(100% - 50px)" }}>
                <div style={{ width: "100%", height: "36px", }}>
                    <ProjectToolBar AccountData={AccountData} onSelectionChanged={onSelectionChangeds} />
                    {/* ToolBarRef={dataRef} onSelectionChanged={onSelectionChangeds} SelectBoxClick={SelectBoxData} */}
                </div>
                <div style={{ width: "100%", height: "calc(100% - 40px)", borderTop: "1px solid #ccc", marginTop: "6px", marginBottom: "5px" }}>
                    <DataStructure AccountData_ID={AccountData_ID} DefaultData_ID={DefaultData_ID} />
                </div>
                <DevToolBar.Default className='FooterItemStyle'>
                    <Item location="before" >
                        <div>
                            <span>期末 资产总计:571239762.7601 负债和股东权益总计:210645737.2001 差额:360594025.56</span>
                        </div>
                    </Item>
                </DevToolBar.Default>
            </div >
        </>
    )
}

export default statementProject